from playerlib import getPlayer
from superdice.libs.diceConfigs import configFile
from superdice.superdice import registerRoll, unregisterRoll, players

def es_map_start(ev):
    cfgData.execute()

def unload():
    unregisterRoll(diceRoll)

def player_spawn(ev):
    players[ev['userid']]['vampire'] = False

def player_hurt(ev):
    attacker = ev['attacker']
    if not attacker in players:
        return
    
    if not players[attacker]['vampire'] or int(ev['es_attackerdead']):
        return

    regen = int(round(float(ev['dmg_health']) / float(divider)))
    if regen < 1:
        return

    getPlayer(attacker).health += regen

def diceRoll(userid, player, eplayer):
    players[userid]['vampire'] = True

cfgData = configFile('dice_vampire')
divider = cfgData.cvar('superdice_cfg_vampire_vampire', 3.0, 'What is the divider for the health recieved based on damage given.')
cfgData.write()
cfgData.execute()

registerRoll(diceRoll, 'vampire')
